package com.sdgakj.repository;

import com.sdgakj.entity.Feed;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.math.BigDecimal;
import java.util.List;

public interface FeedDao extends PagingAndSortingRepository<Feed, Long>, JpaSpecificationExecutor<Feed> {

	@Query(value = "SELECT * FROM f_feed WHERE user_id = ?1 AND tag_id = ?2 AND f_id = ?3", nativeQuery = true)
	List<Feed> findByUserIdAndTagIdAndFId(Long var1, Long var2, Long var3);

	@Query(value = "SELECT * FROM f_feed WHERE user_id = ?1 AND tag_id = ?2 and deltag='0' order by create_date desc", nativeQuery = true)
	List<Feed> findByUserIdAndTagId(Long var1, Long var2);
	/**
	 * 通过家族和类型id查询贴子信息
	 * */
	@Query(value = "SELECT * FROM f_feed WHERE f_id = ?1 AND tag_id = ?2 order by create_date desc", nativeQuery = true)
	List<Feed> findByFamilyAndTagId(Long familyId, Long tagId);

	@Query(value = "SELECT * FROM f_feed order by create_date desc", nativeQuery = true)
	List<Feed> findFeedAll();

//	@Query(value = "select * from f_feed where tag_id=?1 and f_id=?2",nativeQuery = true)
//	List<Feed> findByTagIdAndFamilyId(Long tagId,Long familyId);
    /*@Query(value = "SELECT * FROM f_feed WHERE user_id = ?1 AND id = ?2 AND like_count = ?3", nativeQuery = true)
    List<Feed> findByUserIdAndCommentAndLikecount(Long var1, Long var2, Long var3);*/

	/*  第三条 yl 增加*/
	//Feed findByUserIdAndFeedIdAndLikeCount(Long userId, Long feedId, Long likeCount);
	/**
	 * 时间轴帖子
	 * 
	 * @param customerId
	 * @param tagId
	 * @param sinceId
	 * @param maxId
	 * @param pageSize
	 * @return
	 */
    public List<Feed> findTimeline(Long customerId, Long tagId, Integer isTop, Long sinceId, Long maxId,
								   Integer pageSize);
    /**
     * 查询置顶feed数
     * 
     * @return
     */
    @Query(value = "SELECT COUNT(1) FROM f_feed WHERE deltag = '0' AND is_top = '1' ", nativeQuery = true)
	BigDecimal getTopCount(); 
    
    /**
     * 查询置顶feed
     * 
     * @return
     */
    @Query(value = "SELECT * FROM f_feed WHERE deltag = '0' AND is_top = '1' ORDER BY top_date DESC", nativeQuery = true)
    List<Feed> getTopFeeds();

	List<Feed> getFeedLikeTitle(String content);
	/**
	 * @return 通过用户查到的集合
	 * */
	@Query(value = "select * from f_feed where user_id=?1 order by create_date desc ",nativeQuery = true)
	List<Feed> getFeedListByUser(Long userId);

	@Query(value = "select * from f_feed where f_id=?1 order by create_date desc ",nativeQuery = true)
	List<Feed> getFeedListByFamily(Long familyid);
}
